home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / gfx / show / PhotoCDAGA10.lha / PhotoCDAGA / developer / NOTES < prev   
Text File  |  1994-05-05  |  3KB  |  76 lines

  1. NOTES about EncodeHAM.asm
  2.  
  3. * EncodeHAM.asm contains versions for 68000 and 68020+ processors.
  4.   (if the symbol MC68020 is defined you will get the 68020+ version)
  5.  
  6. * it also contains the brute-force colormap search routine used
  7.   for colormap conversion
  8.  
  9. * when using gcc you have to define the symbol GCC because it stores
  10.   all items as longwords on the stack when doing a function call
  11.   gcc pads all structures that contain just chars; a structure like 
  12.     struct test { char a,b,c};
  13.   will have size 4
  14.   (therefore EncodeHAM.asm contains fixes to solve these problems)
  15.  
  16. * Here comes a short test program for the HAM encoder:
  17.   (it also shows how to use it in your own programs)
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22.   extern void EncodeHAM(unsigned char *yorig, unsigned char *yham,
  23.                         unsigned char *ColorTable, short NumColors, short xsize);
  24.  
  25.   extern unsigned short MaxError, MaxErrorPos;
  26.  
  27.   #define HAM8 1
  28.   #define HAM6 0
  29.   #define XSIZE 3 /* size of the row in pixel */
  30.   #define NUMCOLORS 3  /* number of valid colors in the colortable */
  31.  
  32.   unsigned char yorig[XSIZE*3] = {63,63,63, 0,15,15, 0,15,15}; /* original row in rgbrgb format */
  33.  
  34.   unsigned char yham[XSIZE] = {0}; /* HAM row to encode */
  35.   /* allocate at least (((XSIZE+15)>>4)<<4) bytes if you want to display */
  36.   /* the row using graphics.library calls (see later)                    */
  37.      
  38.   unsigned char ColorTable[NUMCOLORS*3] = {0,0,0, 15,0,15, 15,0,15}; /* ColorTable in brgbrg format */
  39.  
  40.   /* needed by the assembly language part */
  41.   unsigned short ConvertMode = HAM8;
  42.   unsigned short Mult_Table[2*256];
  43.   unsigned char *ColorCache;
  44.   char *Mult_Table32; /* not needed by HAM code */
  45.  
  46.   main()
  47.   {
  48.    int i;
  49.    int counter=0;
  50.    if(ColorCache = calloc(262145, 1))
  51.    {
  52.      /* create the multiplication table */
  53.      for(i=-255; i<256; i++) Mult_Table[i+255] = (unsigned short)(i*i);
  54.  
  55.      EncodeHAM(yorig, yham, ColorTable, NUMCOLORS*3, XSIZE);
  56.  
  57.      for(i=0; i<XSIZE;i++) printf("%02hX ", (unsigned short)yham[i]);
  58.      printf("\n");
  59.      printf("MaxError %hu at pos %hu.\n", MaxError, MaxErrorPos);
  60.    
  61.      for(i=0; i<262145; i++) if(ColorCache[i]) counter++;
  62.      printf("ColorCache has %d entries.\n", counter);
  63.  
  64.      free(ColorCache);
  65.    }
  66.    else printf("Could not allocate ColorCache.\n");
  67.   } 
  68.  
  69.  
  70. * if you want to display the row use WritePixelLine8() or WriteChunkyPixels()
  71.   (use WriteChunkyPixels() only with graphics.library V40 or higher and only if
  72.   a special chunky->planar hardware is present; see autodocs for more)
  73.  
  74.   example: WritePixelLine8(rp, 0, row, XSIZE, yham, temprp);
  75.  
  76.   (see the file DisplayGfx.c for more)